// src/store/Modules.ts

export default {
    auth: {
        namespaced: true,
        state: {
            username: "",
            userId: "",
            token: ""
        },
        mutations: {
            setToken(_state: any, token: string) {
                if (token) {
                    _state.token = token
                } else {
                    _state.token = ""
                }
            },
            setUserName(_state: any, username: string) {
                if (username) {
                    _state.username = username
                } else {
                    _state.username = ""
                }
            },
            setUserId(_state: any, userId: string) {
                if (userId) {
                    _state.userId = userId
                } else {
                    _state.userId = ""
                }
            },
        },
        actions: {
            setToken(context: any, token: string) {
                context.commit('setToken', token)
            },
            setUserName(context: any, username: string) {
                context.commit('setUserName', username)
            },
            setUserId(context: any, userId: string) {
                context.commit('setUserId', userId)
            },
            logout(context: any){
                context.commit('setToken')
                context.commit('setUserName')
                context.commit('setUserId')
            }
        },
        getters: {
            getToken(_state: any, _getters: any): string {
                return _state.token
            },
            getUserName(_state: any, _getters: any): string {
                return _state.username
            },
            getUserId(_state: any, _getters: any): string {
                return _state.userId
            }
        }
    }
}